﻿using System;
using UnityEngine;

namespace RenderHeads.Media.AVProVideo.Demos
{
	// Token: 0x0200000C RID: 12
	public class ChangeAudioTrack : MonoBehaviour
	{
		// Token: 0x0600003A RID: 58 RVA: 0x00003AEC File Offset: 0x00001CEC
		private void OnEnable()
		{
			this._isQueued = true;
		}

		// Token: 0x0600003B RID: 59 RVA: 0x00003AF8 File Offset: 0x00001CF8
		private void Update()
		{
			if (this._isQueued && this.IsVideoLoaded())
			{
				ChangeAudioTrack.DoChangeAudioTrack(this._mediaPlayer, this._trackIndex);
				this._isQueued = false;
			}
		}

		// Token: 0x0600003C RID: 60 RVA: 0x00003B2C File Offset: 0x00001D2C
		private bool IsVideoLoaded()
		{
			return this._mediaPlayer != null && this._mediaPlayer.Info != null && this._mediaPlayer.Control.HasMetaData();
		}

		// Token: 0x0600003D RID: 61 RVA: 0x00003B64 File Offset: 0x00001D64
		private static bool DoChangeAudioTrack(MediaPlayer mp, int index)
		{
			bool result = false;
			int audioTrackCount = mp.Info.GetAudioTrackCount();
			if (index >= 0 && index < audioTrackCount)
			{
				mp.Control.SetAudioTrack(index);
				result = true;
			}
			else
			{
				GlobalData.Debug_LogWarning("[AVProVideo] Audio track index is out of range: " + index);
			}
			return result;
		}

		// Token: 0x0400002F RID: 47
		public MediaPlayer _mediaPlayer;

		// Token: 0x04000030 RID: 48
		public int _trackIndex;

		// Token: 0x04000031 RID: 49
		private bool _isQueued;
	}
}
